package com.dx.mes.common.dao.impl;

import com.dx.common.table.ppt.*;
import com.dx.mes.common.core.dao.impl.GenericHibernateDao;
import com.dx.mes.common.dao.IBisOpeDao;
import com.dx.mes.common.dao.IBisPathDao;
import com.dx.mes.common.dao.IBisPathiDao;
import com.dx.mes.common.table.rtnBean.NxOpeAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import static com.dx.mes.common.bean.def.GenericDef._SPACE0;

@Repository
public class BisOpeHibernateDao extends GenericHibernateDao<Bis_ope, Bis_opeId> implements IBisOpeDao {
	@Autowired
	private IBisPathiDao bisPathiDao;

	@Autowired
	private IBisPathDao bisPathDao;
	
	public NxOpeAll getNxOpeInfo(String pathID, String pathVer, String crOpeNO) {
		NxOpeAll nxOpeAll = new NxOpeAll();

		Bis_pathi pathi = new Bis_pathi();
		Bis_path path = new Bis_path();
		Bis_path nxPath = new Bis_path();
		Bis_ope nxOpe = new Bis_ope();

		Bis_pathiId bisPathiId = new Bis_pathiId();
		Bis_pathId bisPathId = new Bis_pathId();
		Bis_pathId nxBisPathId = new Bis_pathId();
		Bis_opeId bisOpeId = new Bis_opeId();
		
		bisPathiId.setPath_id(pathID);
		bisPathiId.setPath_ver(pathVer);
		pathi = bisPathiDao.get(bisPathiId);

		bisPathId.setPath_id_fk(pathID);
		bisPathId.setPath_ver_fk(pathVer);
		bisPathId.setCr_ope_no(crOpeNO);
		path = bisPathDao.get(bisPathId);
		if (_SPACE0.equals(path.getNx_ope_no()) ||(_SPACE0.equals(path.getNx_ope_no()))|| (null == path.getNx_ope_no())) {
			nxPath = null;
			nxOpe = null;
		}else{
			nxBisPathId.setPath_id_fk(pathID);
			nxBisPathId.setPath_ver_fk(pathVer);
			nxBisPathId.setCr_ope_no(path.getNx_ope_no());
			nxPath = bisPathDao.get(nxBisPathId);
	
			bisOpeId.setOpe_id(nxPath.getCr_ope_id_fk());
			bisOpeId.setOpe_ver(nxPath.getCr_ope_ver_fk());
			nxOpe = this.get(bisOpeId);
		}
		nxOpeAll.setNxPathi(pathi);
		nxOpeAll.setNxPath(nxPath);
		nxOpeAll.setNxOpe(nxOpe);
		
		return nxOpeAll;
	}
}
